<template>
  <div class="app-container">
    <div class="searchContianer" :style="{height:showSearch ? '' : '49px',overflow:'hidden'}"> 
      <div class="searchLeft" :style="{height:showSearch ? '' : '49px',overflow:'hidden'}">
        <el-form :model="queryParams" ref="queryForm" :inline="true" size="small" label-width="68px">
          <el-form-item label="订单编号" prop="orderNo" class="mb8">
            <el-input
              v-model="queryParams.orderNo"
              placeholder="请输入订单编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="服务类型" prop="serverTypeId" class="mb8">
            <el-select v-model="queryParams.serverTypeId" placeholder="请输入服务类型" clearable size="small">
              <el-option label="全部" value="" />
              <el-option v-for="un in serverTypes" :value="un.id" :label="un.name" :key="un.id"/>
            </el-select>
          </el-form-item>
          <el-form-item label="联系电话" prop="contactMobile" class="mb8">
            <el-input
              v-model="queryParams.contactMobile"
              placeholder="请输入联系电话"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="服务状态" prop="serverState" class="mb8">
            <el-input
              v-model="queryParams.serverState"
              placeholder="请输入服务状态"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="订单状态" prop="status" class="mb8">
            <el-input
              v-model="queryParams.status"
              placeholder="请输入订单状态"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-form>
      </div>
      <div class="searchRight">
        <div style="margin-bottom:20px;margin-top:5px">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </div>
      </div>
    </div>

    

      <el-card>
          <el-tabs v-model="activeName">
            <el-tab-pane label="全部" name="all">
            </el-tab-pane>
            <el-tab-pane label="待支付" name="store1">
            </el-tab-pane>
            <el-tab-pane label="待派单" name="store2">
            </el-tab-pane>
            <el-tab-pane label="待接单" name="store3">
            </el-tab-pane>
            <el-tab-pane label="已派单" name="store4">
            </el-tab-pane>
            <el-tab-pane label="待上门" name="store5">
            </el-tab-pane>
            <el-tab-pane label="服务中" name="store6">
            </el-tab-pane>
            <el-tab-pane label="待审核" name="store7">
            </el-tab-pane>
            <el-tab-pane label="待评价" name="store8">
            </el-tab-pane>
            <el-tab-pane label="已完成" name="store9">
            </el-tab-pane>
            <el-tab-pane label="已取消" name="store10">
            </el-tab-pane>
          </el-tabs>
      </el-card>
    <el-table ref="tables" v-loading="loading" border :data="orderList" @selection-change="handleSelectionChange"
    	 :default-sort="defaultSort" @sort-change="handleSortChange" :height="bigTableData">
      <el-table-column type="selection" width="55" align="center" fixed="left"/>
      <el-table-column label="订单编号" align="left" prop="orderNo" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户ID" align="left" prop="customerId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户签约类型" align="left" prop="customerSignedType" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="产品在保状态" align="left" prop="productInServer" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="服务类型ID" align="left" prop="serverTypeId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="服务类型名称" align="left" prop="serverTypeName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="问题类型ID" align="left" prop="problemTypeId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="问题类型名称" align="left" prop="problemTypeName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户姓名" align="left" prop="customeName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户手机号" align="left" prop="customeMobile" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="产品类型ID" align="left" prop="productCategoryId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="产品类型名称" align="left" prop="productCategoryName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户产品ID" align="left" prop="customerProductId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户产品名称" align="left" prop="customerProductName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户产品型号" align="left" prop="customerProductModeNo" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户产品质保期至" align="left" prop="customerProductExpireDate" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.customerProductExpireDate, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户门店ID" align="left" prop="customerStoreId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户门店名称" align="left" prop="customerStoreName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="上门时间" align="left" prop="onsiteDate" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.onsiteDate, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="应付金额" align="left" prop="payableAmount" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="实付金额" align="left" prop="paidAmount" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="付款时间" align="left" prop="payTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户地址ID" align="left" prop="customeAddressId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="联系人" align="left" prop="contactName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="联系方式" align="left" prop="contactMobile" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="省ID" align="left" prop="provinceId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="省名" align="left" prop="provinceName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="市ID" align="left" prop="cityId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="市名" align="left" prop="cityName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="区ID" align="left" prop="districtId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="区名" align="left" prop="districtName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="详细地址" align="left" prop="address" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="纬度" align="left" prop="latitude" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="经度" align="left" prop="longitude" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="指派工程师" align="left" prop="assignEngineerId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="指派时间" align="left" prop="assignTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.assignTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户端显示(1是0否)" align="left" prop="isShowCustomer" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="师傅端显示(1是0否)" align="left" prop="isShowEngineer" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="运营端显示(1是0否)" align="left" prop="isShowOperate" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="服务状态" align="left" prop="serverState" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="订单状态" align="left" prop="status" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="操作" align="left" fixed="right" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view"
            @click="handleDetail(scope.row)" v-hasPermi="['vanger:order:query']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate(scope.row)" v-hasPermi="['vanger:order:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete"
            @click="handleDelete(scope.row)" v-hasPermi="['vanger:order:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改vorder对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="85%" append-to-body :close-on-click-modal="false"
       @close="closeDialog" class="abow_dialog">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :disabled="showDetail">
        <el-form-item label="ID" prop="id">
          <el-input v-model="form.id" placeholder="请输入ID" />
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNo">
          <el-input v-model="form.orderNo" placeholder="请输入订单编号" />
        </el-form-item>
        <el-form-item label="客户ID" prop="customerId">
          <el-input v-model="form.customerId" placeholder="请输入客户ID" />
        </el-form-item>
        <el-form-item label="产品在保状态" prop="productInServer">
          <el-input v-model="form.productInServer" placeholder="请输入产品在保状态" />
        </el-form-item>
        <el-form-item label="服务类型ID" prop="serverTypeId">
          <el-input v-model="form.serverTypeId" placeholder="请输入服务类型ID" />
        </el-form-item>
        <el-form-item label="服务类型名称" prop="serverTypeName">
          <el-input v-model="form.serverTypeName" placeholder="请输入服务类型名称" />
        </el-form-item>
        <el-form-item label="问题类型ID" prop="problemTypeId">
          <el-input v-model="form.problemTypeId" placeholder="请输入问题类型ID" />
        </el-form-item>
        <el-form-item label="问题类型名称" prop="problemTypeName">
          <el-input v-model="form.problemTypeName" placeholder="请输入问题类型名称" />
        </el-form-item>
        <el-form-item label="客户姓名" prop="customeName">
          <el-input v-model="form.customeName" placeholder="请输入客户姓名" />
        </el-form-item>
        <el-form-item label="客户手机号" prop="customeMobile">
          <el-input v-model="form.customeMobile" placeholder="请输入客户手机号" />
        </el-form-item>
        <el-form-item label="产品类型ID" prop="productCategoryId">
          <el-input v-model="form.productCategoryId" placeholder="请输入产品类型ID" />
        </el-form-item>
        <el-form-item label="产品类型名称" prop="productCategoryName">
          <el-input v-model="form.productCategoryName" placeholder="请输入产品类型名称" />
        </el-form-item>
        <el-form-item label="客户产品ID" prop="customerProductId">
          <el-input v-model="form.customerProductId" placeholder="请输入客户产品ID" />
        </el-form-item>
        <el-form-item label="客户产品名称" prop="customerProductName">
          <el-input v-model="form.customerProductName" placeholder="请输入客户产品名称" />
        </el-form-item>
        <el-form-item label="客户产品型号" prop="customerProductModeNo">
          <el-input v-model="form.customerProductModeNo" placeholder="请输入客户产品型号" />
        </el-form-item>
        <el-form-item label="客户产品质保期至" prop="customerProductExpireDate">
          <el-date-picker clearable
            v-model="form.customerProductExpireDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择客户产品质保期至">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客户门店ID" prop="customerStoreId">
          <el-input v-model="form.customerStoreId" placeholder="请输入客户门店ID" />
        </el-form-item>
        <el-form-item label="客户门店名称" prop="customerStoreName">
          <el-input v-model="form.customerStoreName" placeholder="请输入客户门店名称" />
        </el-form-item>
        <el-form-item label="上门时间" prop="onsiteDate">
          <el-date-picker clearable
            v-model="form.onsiteDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择上门时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="应付金额" prop="payableAmount">
          <el-input v-model="form.payableAmount" placeholder="请输入应付金额" />
        </el-form-item>
        <el-form-item label="实付金额" prop="paidAmount">
          <el-input v-model="form.paidAmount" placeholder="请输入实付金额" />
        </el-form-item>
        <el-form-item label="付款时间" prop="payTime">
          <el-date-picker clearable
            v-model="form.payTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择付款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客户地址ID" prop="customeAddressId">
          <el-input v-model="form.customeAddressId" placeholder="请输入客户地址ID" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactName">
          <el-input v-model="form.contactName" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contactMobile">
          <el-input v-model="form.contactMobile" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="省ID" prop="provinceId">
          <el-input v-model="form.provinceId" placeholder="请输入省ID" />
        </el-form-item>
        <el-form-item label="省名" prop="provinceName">
          <el-input v-model="form.provinceName" placeholder="请输入省名" />
        </el-form-item>
        <el-form-item label="市ID" prop="cityId">
          <el-input v-model="form.cityId" placeholder="请输入市ID" />
        </el-form-item>
        <el-form-item label="市名" prop="cityName">
          <el-input v-model="form.cityName" placeholder="请输入市名" />
        </el-form-item>
        <el-form-item label="区ID" prop="districtId">
          <el-input v-model="form.districtId" placeholder="请输入区ID" />
        </el-form-item>
        <el-form-item label="区名" prop="districtName">
          <el-input v-model="form.districtName" placeholder="请输入区名" />
        </el-form-item>
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="指派工程师" prop="assignEngineerId">
          <el-input v-model="form.assignEngineerId" placeholder="请输入指派工程师" />
        </el-form-item>
        <el-form-item label="指派时间" prop="assignTime">
          <el-date-picker clearable
            v-model="form.assignTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择指派时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客户端显示(1是0否)" prop="isShowCustomer">
          <el-input v-model="form.isShowCustomer" placeholder="请输入客户端显示(1是0否)" />
        </el-form-item>
        <el-form-item label="师傅端显示(1是0否)" prop="isShowEngineer">
          <el-input v-model="form.isShowEngineer" placeholder="请输入师傅端显示(1是0否)" />
        </el-form-item>
        <el-form-item label="运营端显示(1是0否)" prop="isShowOperate">
          <el-input v-model="form.isShowOperate" placeholder="请输入运营端显示(1是0否)" />
        </el-form-item>
        <el-form-item label="服务状态" prop="serverState">
          <el-input v-model="form.serverState" placeholder="请输入服务状态" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="!showDetail">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, listUnion, getOrder, getInfoUnion, delOrder, addOrder, updateOrder, exportOrder } from "@/api/vanger/order";
import { getServerTypes } from "@/api/vanger/skcommon";

export default {
  name: "Order",
  data() {
    return {
      // 表格高度
      bigTableData:'',
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // vorder表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查看详情
      showDetail: false,
      // 默认排序
      defaultSort: {prop: 'createTime', order: 'descending'},
      // 查询参数
      queryParams: {
        params: {},
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        customerId: null,
        customerSignedType: null,
        productInServer: null,
        serverTypeId: null,
        serverTypeName: null,
        problemTypeId: null,
        problemTypeName: null,
        customeName: null,
        customeMobile: null,
        productCategoryId: null,
        productCategoryName: null,
        customerProductId: null,
        customerProductName: null,
        customerProductModeNo: null,
        customerProductExpireDate: null,
        customerStoreId: null,
        customerStoreName: null,
        onsiteDate: null,
        payableAmount: null,
        paidAmount: null,
        payTime: null,
        customeAddressId: null,
        contactName: null,
        contactMobile: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        districtId: null,
        districtName: null,
        address: null,
        latitude: null,
        longitude: null,
        assignEngineerId: null,
        assignTime: null,
        isShowCustomer: null,
        isShowEngineer: null,
        isShowOperate: null,
        serverState: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "ID不能为空", trigger: "blur" }
        ],
      },
      //服务类型
      serverTypes: [],

    };
  },
  created() {
    this.getServerTypeList();
    this.handleSortChange(this.defaultSort);
  },
  mounted() {
    this.bigTableData = document.body.clientHeight - document.getElementsByClassName('searchLeft')[0].offsetHeight - 220 + 'px'
  },
  watch: {
    showSearch() {
      this.$nextTick(function () {
        this.bigTableData = document.body.clientHeight - document.getElementsByClassName('searchLeft')[0].offsetHeight - 220 + 'px'
      })
    }
  },
  methods: {

    getServerTypeList(){
      getServerTypes().then(response => {
        this.serverTypes = response.data;
      });
    },
  
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    /** 查询vorder列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.closeDialog()
    },
	// 关闭时设置
    closeDialog() {
      this.open = false;
      this.showDetail = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        customerId: null,
        customerSignedType: null,
        productInServer: null,
        serverTypeId: null,
        serverTypeName: null,
        problemTypeId: null,
        problemTypeName: null,
        customeName: null,
        customeMobile: null,
        productCategoryId: null,
        productCategoryName: null,
        customerProductId: null,
        customerProductName: null,
        customerProductModeNo: null,
        customerProductExpireDate: null,
        customerStoreId: null,
        customerStoreName: null,
        onsiteDate: null,
        payableAmount: null,
        paidAmount: null,
        payTime: null,
        customeAddressId: null,
        contactName: null,
        contactMobile: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        districtId: null,
        districtName: null,
        address: null,
        latitude: null,
        longitude: null,
        assignEngineerId: null,
        assignTime: null,
        isShowCustomer: null,
        isShowEngineer: null,
        isShowOperate: null,
        serverState: null,
        status: 0,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.params = {};
      this.resetForm("queryForm");
      // this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order)
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加vorder";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改vorder";
      });
    },
    
    /** 查看按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看vorder";
        this.showDetail = true;
      });
    },
    
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除vorder编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('vanger/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
